//
//  AY_SplashAd.m
//  AiYue
//
//  Created by xyh on 2025/1/25.
//

#import "AY_SplashAd.h"
@interface AY_SplashAd()

@property (nonatomic, copy) void(^cloaseAdBlock)(BOOL);
@property (nonatomic, copy) void(^loadSuccessBlock)(BOOL);
@end
@implementation AY_SplashAd
// 创建广告对象
- (void)p_buildAdandWithCloseAdBlock:(void(^)())cloaseAdBlock andWithLoadSuccessBlock:(void(^)())loadSuccessBlock {
    BUAdSlot *slot = [[BUAdSlot alloc]init];
    slot.ID = @"103389261"; // 聚合功能使用广告位ID；仅CSJ接入使用代码位ID
    // 兜底广告配置
    slot.mediation.splashUserData = ({
        BUMSplashUserData *splashUserData = [[BUMSplashUserData alloc] init];
        splashUserData.adnName = @"pangle";
        splashUserData.rit = @"890891152";
        // 设置兜底代码位时，当'adnName = pangle'时'appID'需与初始化时应用ID保持一致
        splashUserData.appID = @"5658049";
        splashUserData;
    });
    self.splashAd = [[BUSplashAd alloc] initWithSlot:slot adSize:CGSizeZero];
    self.splashAd.delegate = self;
    [self.splashAd loadAdData];
self.loadSuccessBlock = ^(BOOL successBlock) {
    if(loadSuccessBlock){
        loadSuccessBlock();
    }
};
self.cloaseAdBlock = ^(BOOL cloaseAd) {
    if(cloaseAdBlock){
        cloaseAdBlock();
    }
};
}

// 广告物料、素材加载成功后，会回调splashAdLoadSuccess：方法，
// 在这里调用show方法展示广告
#pragma mark - BUSplashAdDelegate
- (void)splashAdLoadSuccess:(nonnull BUSplashAd *)splashAd {
    if (self.splashAd) {
        if(self.loadSuccessBlock){
            self.loadSuccessBlock(YES);
        }
    }
}

- (void)splashAdDidClick:(nonnull BUSplashAd *)splashAd {
    NSLog(@"splashAdDidClick");
}


- (void)splashAdDidClose:(nonnull BUSplashAd *)splashAd closeType:(BUSplashAdCloseType)closeType {
    if(self.cloaseAdBlock){
        self.cloaseAdBlock(NO);
    }
    NSLog(@"splashAdDidClose");
}


- (void)splashAdDidShow:(nonnull BUSplashAd *)splashAd {
    NSLog(@"splashAdDidShow");
}


- (void)splashAdLoadFail:(nonnull BUSplashAd *)splashAd error:(BUAdError * _Nullable)error {
    NSLog(@"splashAdLoadFail");
    if(self.cloaseAdBlock){
        self.cloaseAdBlock(NO);
    }
}


- (void)splashAdRenderFail:(nonnull BUSplashAd *)splashAd error:(BUAdError * _Nullable)error {
    NSLog(@"splashAdRenderFail");
    if(self.cloaseAdBlock){
        self.cloaseAdBlock(NO);
    }
}


- (void)splashAdRenderSuccess:(nonnull BUSplashAd *)splashAd {
    NSLog(@"splashAdRenderSuccess");
}


- (void)splashAdViewControllerDidClose:(nonnull BUSplashAd *)splashAd {
    NSLog(@"splashAdViewControllerDidClose");
        // 使用聚合功能
    [splashAd.mediation destoryAd];
}


- (void)splashAdWillShow:(nonnull BUSplashAd *)splashAd {
    NSLog(@"splashAdWillShow");
}


- (void)splashDidCloseOtherController:(nonnull BUSplashAd *)splashAd interactionType:(BUInteractionType)interactionType {
    NSLog(@"splashDidCloseOtherController");
}


- (void)splashVideoAdDidPlayFinish:(nonnull BUSplashAd *)splashAd didFailWithError:(NSError * _Nullable)error {
    
}


- (void)splashCardReadyToShow:(nonnull BUSplashAd *)splashAd {
    
}

- (void)splashCardViewDidClick:(nonnull BUSplashAd *)splashAd {
    
}

- (void)splashCardViewDidClose:(nonnull BUSplashAd *)splashAd {
    
}

- (void)splashZoomOutReadyToShow:(nonnull BUSplashAd *)splashAd {
    
}

- (void)splashZoomOutViewDidClick:(nonnull BUSplashAd *)splashAd {
    
}

- (void)splashZoomOutViewDidClose:(nonnull BUSplashAd *)splashAd {
    
}


@end
